require ("test_csbuf")


local function isEqual(a, b)
	if a ~= b then
		print ("no equal", a, b)
	end
end

local parser = CsbufParser:new()
local a = 2
local b = 6000
local c = 123456789
local d = 123456789123
local e = 1.11
local f = "just test"
local aa = -2
local bb = -6000
local cc = -123456789
local dd = -123456789123
local g = true
local h = 2.2234


parser:setUint8(a, 1);
parser:setUint16(b, 2);
parser:setUint32(c, 3);
parser:setUint64(d, 4);
parser:setDouble(e, 5);
parser:setString(f, 6);
parser:setInt8(aa, 7);
parser:setInt16(bb, 8);
parser:setInt32(cc, 9);
parser:setInt64(dd, 10);
parser:setBool(g, 11);
parser:setDouble(h, 12);

local p2 = CsbufParser:new()
p2:setData(parser)
isEqual(p2:getUint8(1), a);
isEqual(p2:getUint16(2), b);
isEqual(p2:getUint32(3), c);
isEqual(p2:getUint64(4), d);
isEqual(p2:getDouble(5), e);
isEqual(p2:getString(6), f);
isEqual(p2:getInt8(7), aa);
isEqual(p2:getInt16(8), bb);
isEqual(p2:getInt32(9), cc);
isEqual(p2:getInt64(10), dd);
isEqual(p2:getBool(11), g);
isEqual(p2:getDouble(12), h);

local t1 = test.Test1:create()
t1.a_t1 = 1
t1.at_2 = 2;
t1.at3_ = "lua test"
parser:clear()
t1:Marshal(parser)

local t2 = test.Test1:create()
p2:clear()
p2:setData(parser)
t2:Unmarshal(p2)
isEqual(t1.a_t1, t2.a_t1)
isEqual(t1.at_2, t2.at_2)
isEqual(t1.at3_, t2.at3_)
print (t2.a_t1, t2.at_2, t2.at3_)

print ("Test end --------------")